$(document).ready(function() {
	var mySwiper = new Swiper('.swiper-container', {
		//滑动方向
		direction: 'vertical',
        //回调函数，滑块释放时如果触发slider切换则执行
		onSlideChangeStart: function(swiper,even){
			$('.swiper-slide-active').addClass('page-current');
			$('.swiper-slide-prev').removeClass('page-current');
			$('.swiper-slide-prev').children().removeAttr('style');
			$('.swiper-slide-prev').children().children().removeAttr('style');
			$('.swiper-slide-next').removeClass('page-current');
			$('.swiper-slide-next').children().removeAttr('style');
			$('.swiper-slide-next').children().children().removeAttr('style');
		}
	})
});
$(function(){
	//第一页点击事件
    $('#hint1').on('tap',function(){
		//分开时候的手
        $('.hand_breakup').anim({opacity:'0'},1.5);
		//牵手
        $('.hand').anim({opacity:'1'},1.5);
		//头发
		$('.hair').anim({left:'19%',top:'32%'},0.5);
        $(this).css({display:'none'});
		//箭头
		$('.up_arrow').css('display','block');
    });
	//第二页点击事件
	$('#hint2').on('tap',function(){
		//右边手臂
		$('.right_arm').anim({top:'59%',left:'7%'},1.5);
		//上面手臂
		$('.top_arm').anim({top:'49%',left:'8%'},1.5);
		//头部
		$('.head').anim({top:'35%',left:'16.5%'},0.5);
		setTimeout(function(){
			//心
			$('.heard').anim({opacity:'1'},1);
			$('.right_arm').anim({top:'56%',left:'0'},1.5);
			$('.top_arm').anim({top:'47%',left:'2%'},1.5);
			$('.head').anim({top:'34%',left:'15.5%'},0.5);
		},1500);
		$(this).css({display:'none'});
		$('.up_arrow').css('display','block');
	});
	//第三页点击
	$('#hint3').on('tap',function(){
		$('.daugther_arm').anim({transform:'rotateZ(-5deg)',left:'59%',top:'58%'},1.5);
		$('.left_bt_arm').anim({transform:'rotateZ(46deg)',left:'34%',top:'59%'},1.5);
		$(this).css({display:'none'});
		$('.up_arrow').css('display','block');
	});
	//第六页点击
	$('#hint6').on('tap',function(){
		$('.begin').anim({opacity:'0'});
		$('.end').anim({opacity:'1',transform:'translateY(-30px) scaleY(1.2)'},1);
		setTimeout(function(){
			$('.pint_circle1').anim({opacity:'1'},1);
			$('.pint_circle2').anim({opacity:'1'},1);
		},1000);
		$(this).css({display:'none'});
		$('.up_arrow').css('display','block');
	});
	//向妈妈告白
	$('.title29').on('tap',function(){
		$('.mask').addClass('masktap');
		$('.mask').removeClass('masktap1');
	});
	//遮罩
	$('.mask').on('tap',function(){
		$(this).addClass('masktap1');
		$(this).removeClass('masktap');
	})
});
//图片预加载
$(function(){
	//$('#loading').addClass('hide');
	//th.into();
	var imgs = [
			'img/572a0ffda3664e163b0002fc.jpg','img/572a0047a3664e093b0002d6.jpg','img/572a1167a3664e1f3b0002ff.png','img/572b3deca3664eaa29000061.jpg','img/572b4ac2a3664ea2290000a8.jpg',
			'img/572b3627a3664ea72900003e.jpg','img/572b5680a3664e9e2900009c.jpg','img/57299631a3664e283b0000a3.png','img/57299633a3664e273b0000a5.png','img/572a0ffea3664e043b000391.png',
			'img/572a0ffea3664e273b0002a5.png','img/572a1fa6a3664e233b00033a.png','img/572a17bfa3664e083b00031c.png','img/572a17bfa3664efa3a000321.png','img/572a17c0a3664e0c3b0002e1.png',
			'img/572a117ba3664e293b0002bd.png','img/572a0362a3664e013b0002bf.jpg','img/572b3d8aa3664ea929000063.png','img/572b3d89a3664e8929000078.png','img/572b3d89a3664ea229000086.png',
			'img/572b3d89a3664eaa2900005e.png','img/572b4ac2a3664eac2900005d.png','img/572b4ac3a3664e8e29000084.png','img/572b4ac3a3664e9b29000077.png','img/572b4ac3a3664e9029000099.png',
			'img/572b4ac3a3664ea92900008c.png','img/572b4ac4a3664ead290000a8.png','img/572b4d9ca3664eac29000067.png','img/572b7f03a3664e9a290000fc.png','img/572b7f03a3664e8529000124.png',
			'img/572b7f56a3664ea629000123.png','img/572b67a6a3664e97290000df.png','img/572b3627a3664e8a29000047.png','img/572b3627a3664e892900005a.png','img/572b3628a3664e9b29000028.png',
			'img/572b5680a3664e0458000017.png','img/572b5680a3664e962900009d.png','img/572b5680a3664eb3290000a5.png','img/572b5681a3664e89290000bd.png','img/572b5681a3664e0658000013.png',
			'img/5729f7baa3664e273b000254.png','img/5729f668a3664e0c3b000285.png','img/5729f668a3664e053b000295.png','img/5729f668a3664e113b000274.png',
			'img/572987bca3664e0f3b000063.jpg','img/5729f669a3664e133b00029d.png','img/57299d62a3664e143b0000ff.png','img/5729f669a3664e083b0002d6.png'],
		n = imgs.length, i = 0;
	function loadImage(url, callback) {
		var img = new Image();
		img.src = url;
		//complete 属性可返回浏览器是否已完成对图像的加载。
		//如果加载完成，则返回 true，否则返回 fasle。
		if (img.complete) {
			callback();
			return;
		}
		//加载完成执行回调函数函数
		img.onload = function () {
			callback();
			return;
		}
		//加载图片错误执行回调函数
		img.onerror = function () {
			callback();
			return;
		}
	}
	function success() {
		if(i < n){
			i++;
		}
		//每加载一张图片 预加载的百分比上升
		var num = parseInt(i/n * 100);
		var data=['1.png','2.png','3.png','4.png','5.png','6.png','7.png','8.png'];
		document.getElementById('heard_img').src='img/'+data[num%8];
		//加载完成时
		if(i==n){
			setTimeout(function(){
				$('.loading').anim({display:'none'},0.5);
				$('.page-1').addClass('page-current');
				//播放背景音乐
				$('.music a').removeClass('off');
				aMusic.play('music');
				isPlay=true;
			}, 500);
			clearInterval(timeImage);
		}
	}
	//每150ms执行一次本函数 并把加载的进度显示到预加载页面
	var timeImage = setInterval(function(){
		loadImage(imgs[i],success);
	}, 150);
	//音乐
	var aMusic={
		tracks:{},
		_enabled:true,
		enable:function(){
			aMusic._enabled=true;
		},
		disable:function(){
			aMusic._enabled=false;
		},
		load:function(url,loop){
			if($('#'+url).html()==null){
				if(loop){
					$('.music').append('<audio src="music/'+url+'.mp3" id="'+url+'"  loop></audio>');
				}
			}
		},
		play:function(url){
			var oAudio=document.getElementById(url);
			oAudio.play();
		},
		stop:function(url){
			var oAudio=document.getElementById(url);
			oAudio.pause();
		}
	};
	aMusic.load('music',true);
	//aMusic.load('sui');
	//点击图标 播放音乐
	$('.music a').addClass('off');
	var isPlay=false;
	$('.music a').on('touchstart',function(){
		if(!$(this).hasClass('off')){
			$('.music a').addClass('off');
			aMusic.stop('music');
			isPlay=false;
		}
		else{
			$('.music a').removeClass('off');
			aMusic.play('music');
			isPlay=true;
		}
	})
});